import sys
import common

#if len(sys.argv)<2:
#     print("usage:")
#     exit(0)

myfile = open('dex-layout.txt', "r")

l=[]
ll=[]

for line in (myfile):
	s=line.strip(' \t\n')
	if len(s)<1:
		continue
		
	if s.startswith('#'):
		continue
	
	s1=s.split('\t')
	#print(s1)

	

	ll.append(s1)

print('''
#ifndef dex_format_h
#define dex_format_h
#include "dex-structs.h"


class CDexFile
{
public:
	CDexFile():pFileBase(NULL),length(0) {}
	CDexFile(char*p,int size):pFileBase(p),length(size) {}	
	''')		
for x in ll:
	
	if not x[1].startswith('ubyte'):
		if x[1].endswith(']'):
			s=common.get_cls_name(x[1][:-2])
		else:
			s=common.get_cls_name(x[1])
	else:
		s='ubyte'
	
	if x[0].startswith('link'):
		t='link'
	else:
		t=x[0]
		
	print('\n\t%s *Get%s()'%(s,common.get_name(x[0])))
	if x[0]=='header':
		print('\t{return (%s *)(pFileBase);}'%(s)		)	
	else:
		print('\t{return (%s *)(pFileBase+GetHeader()->%s_off);}'%(s,t))	
		print('\n\tubyte* Get%sAddr()'%(common.get_name(x[0])))	
		print('\t{return (ubyte *)(pFileBase+GetHeader()->%s_off);}'%(t))				
		print('\tint Get%sSize(){return GetHeader()->%s_size;}'%(common.get_name(x[0]),t))		
	
print('''
	CDexMapList *GetMapist()
	{return (CDexMapList *)(pFileBase+GetHeader()->map_off);}
	void print();
	int sprint(char *);
protected:
	char *pFileBase;
	int length;
};

#endif// dex_format_h
	''')